package com.clstu.mhl.service;

import com.clstu.mhl.dao.DiningTableDAO;
import com.clstu.mhl.domain.DiningTable;

import java.util.List;

/**
 * 完成对DiningTable表的各种操作,调用..Dao
 */
public class DiningTableService {
    static DiningTableDAO dao = new DiningTableDAO();
    //方法返回所有的餐桌信息
    public List<DiningTable> listTable(){
        return dao.queryMany("select id,status from dining_table",DiningTable.class);
    }

    //写方法返回某个餐桌的信息//如果为null表示不存在
    public DiningTable getById(String id){
        return dao.querySingle("select * from dining_table where id = ?",DiningTable.class,id);
    }

    //写方法修改餐桌信息,(能订餐的情况下使用) 返回成功或失败
    public boolean setByIdNamePhone(String id,String name,String phone){
        //小技巧,不确定sql语句是否写对先到sql控制台执行一下
        int i = dao.update("update dining_table set status = ?,name = ?,phone=? where id = ?", "有人", name, phone,id);
        return i>0;
    }

    //编写方法,用餐时调用
    public boolean setEatingById(String id){
        //这里的状态只能插入两个字符
        int i = dao.update("update dining_table set status = ? where id = ?", "就餐", id);
        return i>0;
    }

    //编写方法,实现设置餐桌未空位
    public boolean setEmptyById(String id){
        int i = dao.update("update dining_table set status = ?,name = ?,phone=? where id = ?", "空", "", "",id);
        return i>0;
    }

}
